Skip to content
This repository has been archived by the owner on Apr 11, 2024. It is now read-only.

Use EI_CLASS for base ABI encoding. #47

Merged
merged 2 commits into from
Aug 17, 2022

Conversation

scylaac
Copy link
Contributor

@scylaac scylaac commented Apr 19, 2022

No description provided.

Copy link
Contributor

@xen0n xen0n left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为得各下游项目命名一致,可给 0x1 0x2 0x3 起名,例如 EF_LOONGARCH_FPABI_S EF_LOONGARCH_FPABI_F EF_LOONGARCH_FPABI_D 这样。反正 binutils 那边也必须起名。

The ABI type of an ELF object is uniquely identified by `e_flags[7:0]` in its header.
The ABI type of an ELF object is uniquely identified by `e_flags[7:0]` and `EI_CLASS` in its header.
Within this combination, `e_flags[2:0]` and `EI_CLASS` correspond to the **base ABI** type,
where `EI_CLASS` determines how C integral and pointer types are expressed (<<c-lang-data-model, data model>>)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The description of EI_CLASS is inaccurate.

See http://www.sco.com/developers/gabi/latest/ch4.eheader.html

Copy link
Contributor Author

@scylaac scylaac Apr 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这儿不是对 EI_CLASS 本身语义的描述,而是 "借用" EI_CLASS 标记龙芯架构基础 ABI 类型信息,如 ELF32 只容纳 ilp32* ABI 的程序。如果确实容易引起误解的话,应该怎么修改比较好呢?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RISC-V 那边是这么写的:

EI_CLASS
Specifies the base ISA, either RV32 or RV64. We don’t let users link RV32 and RV64 code together.

好像也有这个问题……

改成 "the expression of C integral and pointer types are uniquely determined by EI_CLASS value, we don't support LP64 ABIs with ELFCLASS32 or ILP32 ABIs with ELFCLASS64" 这样?

@scylaac
Copy link
Contributor Author

scylaac commented Apr 19, 2022

为得各下游项目命名一致,可给 0x1 0x2 0x3 起名,例如 EF_LOONGARCH_FPABI_S EF_LOONGARCH_FPABI_F EF_LOONGARCH_FPABI_D 这样。反正 binutils 那边也必须起名。

这个我们再讨论一下吧... base ABI 还是一个整体,不是特别希望 e_flags[2:0] 被视为单独的 "FPABI",否则省出这些编码空间也没有多大灵活性。😂

@xen0n
Copy link
Contributor

xen0n commented Apr 19, 2022

为得各下游项目命名一致,可给 0x1 0x2 0x3 起名,例如 EF_LOONGARCH_FPABI_S EF_LOONGARCH_FPABI_F EF_LOONGARCH_FPABI_D 这样。反正 binutils 那边也必须起名。

这个我们再讨论一下吧... base ABI 还是一个整体,不是特别希望 e_flags[2:0] 被视为单独的 "FPABI",否则省出这些编码空间也没有多大灵活性。:joy:

这可能就是个取名问题,不希望被理解成 FPABI 的话,那我觉得叫 FPABI_MARKER 之类一眼能看出来不是独立组成部分的名字就好了。


[%header,cols="1,1,1,1"]
|====
| Bit 31 - 8 | Bit 7 - 6 | Bit 5 - 3 | Bit 2 - 0
| (reserved) | ABI version | ABI extension | Base ABI
| (reserved) | ABI version | ABI extension | Base ABI (partial)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should give bits[2-0] a better name. Something like 'FP ABI Maker' as @xen0n proposed can be considered?

@scylaac
Copy link
Contributor Author

scylaac commented Jul 25, 2022

感谢提议,要不我们改叫 Base ABI Modifier 吧。

@scylaac scylaac requested a review from SixWeining July 27, 2022 01:59
SixWeining added a commit to llvm/llvm-project that referenced this pull request Aug 16, 2022
…rchTargetStreamer

Reference: https://github.com/loongson/LoongArch-Documentation
The last commit hash (main branch) is:
99016636af64d02dee05e39974d4c1e55875c45b

Note:
There are several PRs [1][2][3] that may affect the e_flags.
After they got closed or merged, we should update the implementation here accordingly.

[1] loongson/LoongArch-Documentation#33
[2] loongson/LoongArch-Documentation#47
[2] loongson/LoongArch-Documentation#61

Differential Revision: https://reviews.llvm.org/D130239
Copy link
Contributor

@ChenghuaXu ChenghuaXu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.

@xen0n
Copy link
Contributor

xen0n commented Aug 16, 2022

起一下 ELF 常量名字?Base ABI Modifier,EF_LOONGARCH_ABIMOD_{S,F,D}? 感觉和一切带 LoongArch 全称的名字一样,太长了。。叫 EF_LOONGARCH_BASE_ABI_MODIFIER_xx 是断然不可接受的,叫 EF_LOONGARCH_BAM_xx 又太晦涩。

@ChenghuaXu
Copy link
Contributor

ChenghuaXu commented Aug 16, 2022

起一下 ELF 常量名字?Base ABI Modifier,EF_LOONGARCH_ABIMOD_{S,F,D}? 感觉和一切带 LoongArch 全称的名字一样,太长了。。叫 EF_LOONGARCH_BASE_ABI_MODIFIER_xx 是断然不可接受的,叫 EF_LOONGARCH_BAM_xx 又太晦涩。
ABI Modifier指位域名称。里面的枚举值简单一些EF_LARCH_S/F/D?

@xen0n
Copy link
Contributor

xen0n commented Aug 16, 2022

起一下 ELF 常量名字?Base ABI Modifier,EF_LOONGARCH_ABIMOD_{S,F,D}? 感觉和一切带 LoongArch 全称的名字一样,太长了。。叫 EF_LOONGARCH_BASE_ABI_MODIFIER_xx 是断然不可接受的,叫 EF_LOONGARCH_BAM_xx 又太晦涩。
ABI Modifier指位域名称。里面的枚举值简单一些EF_LARCH_S/F/D?

现在是叫 EF_LOONGARCH_xxx 的。

/* Processor specific flags for the ELF header e_flags field.  */
/*The flag lp64s/lp64f/lp64d/ilp32s/ilp32f/ilp32d 3bits. */
#define EF_LOONGARCH_ABI_LP64_SOFT_FLOAT        0x1
#define EF_LOONGARCH_ABI_LP64_SINGLE_FLOAT      0x2
#define EF_LOONGARCH_ABI_LP64_DOUBLE_FLOAT      0x3

#define EF_LOONGARCH_ABI_ILP32_SOFT_FLOAT       0x5
#define EF_LOONGARCH_ABI_ILP32_SINGLE_FLOAT     0x6
#define EF_LOONGARCH_ABI_ILP32_DOUBLE_FLOAT     0x7

#define EF_LOONGARCH_ABI_MASK                   0x7
#define EF_LOONGARCH_ABI_ILP32_MASK             0x4
#define EF_LOONGARCH_ABI_FLOAT_MASK             0x3
#define EF_LOONGARCH_ABI_SOFT_FLOAT_MASK        0x1
#define EF_LOONGARCH_ABI_SINGLE_FLOAT_MASK      0x2
#define EF_LOONGARCH_ABI_DOUBLE_FLOAT_MASK      0x3

#define EF_LOONGARCH_ABI(abi)   (EF_LOONGARCH_ABI_MASK & (abi))

#define EF_LOONGARCH_IS_LP64(abi) \
  (EF_LOONGARCH_ABI(abi) && (!(EF_LOONGARCH_ABI(abi) & EF_LOONGARCH_ABI_ILP32_MASK)))
#define EF_LOONGARCH_IS_ILP32(abi) \
  (EF_LOONGARCH_ABI(abi) && (EF_LOONGARCH_ABI(abi) & EF_LOONGARCH_ABI_ILP32_MASK))

#define EF_LOONGARCH_IS_SOFT_FLOAT(abi) \
  (!((EF_LOONGARCH_ABI(abi) & EF_LOONGARCH_ABI_FLOAT_MASK) ^ EF_LOONGARCH_ABI_SOFT_FLOAT_MASK))

#define EF_LOONGARCH_IS_SINGLE_FLOAT(abi) \
  (!((EF_LOONGARCH_ABI(abi) & EF_LOONGARCH_ABI_FLOAT_MASK) ^ EF_LOONGARCH_ABI_SINGLE_FLOAT_MASK))

#define EF_LOONGARCH_IS_DOUBLE_FLOAT(abi) \
  (!((EF_LOONGARCH_ABI(abi) & EF_LOONGARCH_ABI_FLOAT_MASK) ^ EF_LOONGARCH_ABI_DOUBLE_FLOAT_MASK))

那叫 EF_LOONGARCH_ABI_{S,F,D} 其实就好了?或者仍然保留 xxx_ABI_SOFT_FLOAT 这样的较长的形式,改动相对更小。别的定义也相应微调一下就好。

@xen0n
Copy link
Contributor

xen0n commented Aug 16, 2022

/* Processor specific flags for the ELF header e_flags field.  */
/* Base ABI modifier, 3bits. */
#define EF_LOONGARCH_ABI_SOFT_FLOAT        0x1
#define EF_LOONGARCH_ABI_SINGLE_FLOAT      0x2
#define EF_LOONGARCH_ABI_DOUBLE_FLOAT      0x3
#define EF_LOONGARCH_ABI_MODIFIER_MASK     0x7
#define EF_LOONGARCH_ABI_MODIFIER(abi)     (EF_LOONGARCH_ABI_MODIFIER_MASK & (abi))

#define EF_LOONGARCH_IS_SOFT_FLOAT(abi) \
  (EF_LOONGARCH_ABI_MODIFIER(abi) == EF_LOONGARCH_ABI_SOFT_FLOAT)

#define EF_LOONGARCH_IS_SINGLE_FLOAT(abi) \
  (EF_LOONGARCH_ABI_MODIFIER(abi) == EF_LOONGARCH_ABI_SINGLE_FLOAT)

#define EF_LOONGARCH_IS_DOUBLE_FLOAT(abi) \
  (EF_LOONGARCH_ABI_MODIFIER(abi) == EF_LOONGARCH_ABI_DOUBLE_FLOAT)

@ChenghuaXu
Copy link
Contributor

文档是不是可以合了,至于代码中如何改可以参考这个。

/* Processor specific flags for the ELF header e_flags field.  */
/* Base ABI modifier, 3bits. */
#define EF_LOONGARCH_ABI_SOFT_FLOAT        0x1
#define EF_LOONGARCH_ABI_SINGLE_FLOAT      0x2
#define EF_LOONGARCH_ABI_DOUBLE_FLOAT      0x3
#define EF_LOONGARCH_ABI_MODIFIER_MASK     0x7
#define EF_LOONGARCH_ABI_MODIFIER(abi)     (EF_LOONGARCH_ABI_MODIFIER_MASK & (abi))

#define EF_LOONGARCH_IS_SOFT_FLOAT(abi) \
  (EF_LOONGARCH_ABI_MODIFIER(abi) == EF_LOONGARCH_ABI_SOFT_FLOAT)

#define EF_LOONGARCH_IS_SINGLE_FLOAT(abi) \
  (EF_LOONGARCH_ABI_MODIFIER(abi) == EF_LOONGARCH_ABI_SINGLE_FLOAT)

#define EF_LOONGARCH_IS_DOUBLE_FLOAT(abi) \
  (EF_LOONGARCH_ABI_MODIFIER(abi) == EF_LOONGARCH_ABI_DOUBLE_FLOAT)

@ChenghuaXu ChenghuaXu requested a review from yetist August 17, 2022 03:23
Copy link
Contributor

@yetist yetist left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@FreeFlyingSheep FreeFlyingSheep merged commit 6c49901 into loongson:main Aug 17, 2022
thilinarmtb pushed a commit to nomp-org/llvm-project that referenced this pull request Aug 24, 2022
…rchTargetStreamer

Reference: https://github.com/loongson/LoongArch-Documentation
The last commit hash (main branch) is:
99016636af64d02dee05e39974d4c1e55875c45b

Note:
There are several PRs [1][2][3] that may affect the e_flags.
After they got closed or merged, we should update the implementation here accordingly.

[1] loongson/LoongArch-Documentation#33
[2] loongson/LoongArch-Documentation#47
[2] loongson/LoongArch-Documentation#61

Differential Revision: https://reviews.llvm.org/D130239
a4lg pushed a commit to a4lg/binutils-gdb that referenced this pull request Sep 30, 2022
  Update handling of e_flags according to the documentation
  update [1] (discussions [2][3]).

  Object file bitness is now represented in the EI_CLASS byte.
  The e_flags field is now interpreted as follows:

  e_flags[2:0]: Base ABI modifier

  - 0x1: soft-float
  - 0x2: single-precision hard-float
  - 0x3: double-precision hard-float

  e_flags[7:6]: ELF object ABI version

  - 0x0: v0
  - 0x1: v1

  [1]: https://github.com/loongson/LoongArch-Documentation/blob/main/docs/LoongArch-ELF-ABI-EN.adoc#e_flags-identifies-abi-type-and-version
  [2]: loongson/LoongArch-Documentation#61
  [3]: loongson/LoongArch-Documentation#47
xen0n pushed a commit to xen0n/binutils-gdb that referenced this pull request Oct 8, 2022
  Update handling of e_flags according to the documentation
  update [1] (discussions [2][3]).

  Object file bitness is now represented in the EI_CLASS byte.
  The e_flags field is now interpreted as follows:

  e_flags[2:0]: Base ABI modifier

  - 0x1: soft-float
  - 0x2: single-precision hard-float
  - 0x3: double-precision hard-float

  e_flags[7:6]: ELF object ABI version

  - 0x0: v0
  - 0x1: v1

  [1]: https://github.com/loongson/LoongArch-Documentation/blob/main/docs/LoongArch-ELF-ABI-EN.adoc#e_flags-identifies-abi-type-and-version
  [2]: loongson/LoongArch-Documentation#61
  [3]: loongson/LoongArch-Documentation#47

(cherry picked from commit c4a7e6b)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants